package com.test.enc.util;

import java.util.Calendar;

public class DateUtil {

    public static String getCurrentDateTime() {
        Calendar calendar = Calendar.getInstance();
        return getCurrentDateTime(calendar);
    }

    public static String getCurrentDateTime(Calendar calendar) {
        StringBuilder builder = new StringBuilder();
        builder.append(calendar.get(1));
        int month = calendar.get(2) + 1;
        if (month < 10) {
            builder.append(0);
        }

        builder.append(month);
        int date = calendar.get(5);
        if (date < 10) {
            builder.append(0);
        }

        builder.append(date);
        int hour = calendar.get(11);
        if (hour < 10) {
            builder.append(0);
        }

        builder.append(hour);
        int min = calendar.get(12);
        if (min < 10) {
            builder.append(0);
        }

        builder.append(min);
        int sec = calendar.get(13);
        if (sec < 10) {
            builder.append(0);
        }

        builder.append(sec);
        return builder.toString();
    }

}
